package com.zjut.an.acquisitionhistory.manager;

import java.util.List;

import javax.annotation.Resource;

import com.zjut.an.acquisitionhistory.dao.AnAcquisitionHistory;
import com.zjut.an.acquisitionhistory.dao.AnAcquisitionHistoryDAO;
import com.zjut.an.acquisitionhistory.dao.AnAcquisitionHistory;
import com.zjut.an.acquisitionhistory.dao.AnAcquisitionHistoryDAO;
import com.zjut.an.util.module.PageModule;

public class AnAcquisitionHistoryManager {
	
	@Resource(name = "AnAcquisitionHistoryDAO")
	private AnAcquisitionHistoryDAO acquHistoryDAO;
	
	public void saveHistory(AnAcquisitionHistory model){
		acquHistoryDAO.save(model);
	}
	
	public boolean checkExistByProperties(boolean flag, String title){
		return acquHistoryDAO.checkExistByProperties(flag, title);
	}
	
	public int getDataPlaceById(AnAcquisitionHistory model) {		
		String hql = "SELECT COUNT(*) FROM AnAcquisitionHistory  WHERE hiId<="+model.getHiId();
		if (null!=model.getDescription()) {
			hql +=" and description='"+model.getDescription()+"'";
		}
		if (null!=model.getChannelUrl()) {
			hql +=" and channelUrl='"+model.getChannelUrl()+"'";
		}
		int place = acquHistoryDAO.findCountByHql(hql, null);
		return place;
	}
	
	public List<AnAcquisitionHistory> getDataByChannelUrl(String channelUrl) {		
		String hql = " FROM AnAcquisitionHistory WHERE channelUrl='"+channelUrl+"'";
		return acquHistoryDAO.findByHql(1,10000,hql, null);
	}
	
	public List<AnAcquisitionHistory> getDataByDescription(String description) {		
		String hql = " FROM AnAcquisitionHistory WHERE description='"+description+"'";
		return acquHistoryDAO.findByHql(1,10000,hql, null);
	}
	
	public void deleteDatas() {
		List<AnAcquisitionHistory> list = acquHistoryDAO.findAll();
		for (AnAcquisitionHistory obj : list) {
			acquHistoryDAO.delete(obj);
		}
	}
	
	public void deleteDatas(List<AnAcquisitionHistory> list) {
		for (AnAcquisitionHistory obj : list) {
			acquHistoryDAO.delete(obj);
		}
	}
	
	@Resource(name = "AnAcquisitionHistoryDAO")
	private AnAcquisitionHistoryDAO dao;
	
	public void addData(AnAcquisitionHistory obj) {	
		dao.save(obj);
	}
	
	public PageModule getDataByInstance (int pageNumber,int pageSize, String sort, String order, AnAcquisitionHistory obj) {
		return dao.findByInstance(pageNumber, pageSize, sort, order, obj);
	}
	
	public List getDatas() {
		return dao.findAll();
	}
}
